<!--
 * @Author: liuyonghu
 * @Date: 2021-08-18 16:57:29
 * @LastEditTime: 2021-08-18 17:37:18
 * @LastEditors: liuyonghu
 * @Description: 
 * @FilePath: /demos/mqtt.html
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="https://cdn.bootcdn.net/ajax/libs/mqtt/4.2.8/mqtt.min.js"></script>

    <script>
      var client = mqtt.connect("ws://broker-cn.emqx.io/mqtt", { port: 8083 }); // you add a ws:// url here
      client.subscribe("mqtt/demo");

      client.on("message", function (topic, payload) {
        alert([topic, payload].join(": "));
        // client.end();
      });

      client.publish("mqtt/demo", "hello world!");
    </script>
  </body>
</html>
